home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_6.arc / WINDEV.ARC / WINVUE.C < prev    next >
C/C++ Source or Header  |  1989-02-14  |  3KB  |  156 lines

  1. /*
  2.  * Winvue main module
  3.  *
  4.  * Written by Bill Hall
  5.  * 3665  Benton Street, #66
  6.  * Santa Clara, CA 95051
  7.  *
  8.  * See Winvue.doc for usage information
  9.  *
  10.  */
  11.  
  12. /* bypass some things we don't need in windows.h */
  13. #define NOCOMM        
  14. #define NOKANJI
  15. #define NOATOM
  16. #define NOBITMAP
  17. #define NOMINMAX
  18. #include <windows.h>
  19.  
  20. #include <io.h>
  21. #include <stdlib.h>
  22. #include <ttycls.h>
  23.  
  24. #define EXTERN
  25. #include "winvue.h"
  26.  
  27. /* entry point for windows */
  28. int FAR PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  29. HANDLE hInstance, hPrevInstance;
  30. LPSTR lpszCmdLine;
  31. int cmdShow;
  32. {
  33.  
  34.   /* initialize program */
  35.     if (!InitProgram(hInstance,hPrevInstance, lpszCmdLine, cmdShow))
  36.       /* if we fail, then exit */
  37.     return FALSE;
  38.  
  39.   /* fall into the message loop */
  40.     while (TRUE)
  41.     DoMessage();
  42.  
  43. }
  44.  
  45. /* execute GetMessage while waiting for a file to view */
  46. void NEAR DoGetMessage()
  47. {
  48.     MSG msg;
  49.  
  50.     if (GetMessage((LPMSG)&msg,NULL,0,0)) {
  51.     if (TranslateAccelerator(MWnd.hWnd,hAccel,(LPMSG)&msg) == 0) {
  52.         TranslateMessage((LPMSG)&msg);
  53.         DispatchMessage((LPMSG)&msg);
  54.     }
  55.     }
  56.     else
  57.     exit((int)msg.wParam);
  58. }
  59.  
  60. /* 
  61.    Execute PeekMessage while displaying a file so that other Windows
  62.    programs can continue to run.
  63. */
  64. void NEAR DoPeekMessage()
  65. {
  66.     MSG msg;
  67.  
  68.   /* if there is a message, then process it */
  69.     if (PeekMessage((LPMSG)&msg,NULL,0,0,PM_REMOVE)) {
  70.         if (msg.message == WM_QUIT)
  71.         exit((int)msg.wParam);
  72.     if (TranslateAccelerator(MWnd.hWnd,hAccel,(LPMSG)&msg) == 0) {
  73.         TranslateMessage((LPMSG)&msg);
  74.         DispatchMessage((LPMSG)&msg);
  75.     }
  76.     }
  77.   /* otherwise if file is still open process it */
  78.     else if (hFile > 0)
  79.         ProcessFile();
  80. }
  81.  
  82. /* main window procedure */
  83. long FAR PASCAL MainWndProc(hWnd,message,wParam,lParam)
  84. HWND hWnd;
  85. unsigned message;
  86. WORD wParam;
  87. LONG lParam;
  88. {
  89.  
  90.     PAINTSTRUCT ps;
  91.     
  92.     switch(message) {
  93.  
  94.       /* stop and start file display with the mouse button */
  95.     case WM_LBUTTONDOWN:
  96.         if (Pause)
  97.         SendMessage(hWnd, WM_COMMAND, IDM_RESUME,0L);
  98.         else
  99.         SendMessage(hWnd, WM_COMMAND, IDM_PAUSE,0L);
  100.         break;
  101.  
  102.       /* adjust position of text display if window is resized */
  103.     case WM_SIZE:
  104.         AdjustHeight(LOWORD(lParam), HIWORD(lParam));
  105.         break;
  106.  
  107.       /* menu commands */
  108.     case WM_COMMAND:
  109.         WndCommand(hWnd, wParam);
  110.         break;
  111.  
  112.       /* display string from remote program */
  113.     case WM_USER:
  114.         TTYDisplay((PTTYWND)GetWindowWord(hWnd,0),(short)wParam, 
  115.                 (char *)LOWORD(lParam));
  116.         break;
  117.  
  118.       /* initialize some things when window is created */
  119.     case WM_CREATE:
  120.         WndCreate(hWnd,lParam);
  121.         break;
  122.  
  123.       /* quit */
  124.     case WM_DESTROY:
  125.         PostQuitMessage(0);
  126.         break;
  127.  
  128.       /* Close any open files */
  129.     case WM_CLOSE:
  130.         if (hFile > 0)
  131.         close(hFile);
  132.         DestroyWindow(hWnd);
  133.         break;
  134.  
  135.       /* if exiting Windows, close any open files */
  136.     case WM_ENDSESSION:
  137.         if (wParam)
  138.             if (hFile > 0)
  139.             close(hFile);
  140.         break;
  141.  
  142.       /* refresh the window */
  143.     case WM_PAINT:
  144.         BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  145.         MainWndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  146.         EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  147.         break;
  148.  
  149.       /* all other messages are handled by windows */
  150.     default:
  151.         return ((long)DefWindowProc(hWnd,message,wParam,lParam));
  152.         break;
  153.     }
  154.     return(0L);
  155. }
  156.